        PROGRAM HLTEST

        INTEGER HEAP(20000),A(100),I

        INTEGER LLCRHE,LLCRHD,LLCREL,LLCRED,LLFIRS,LLLAST,LLNEXT,LLPREV,
     +          LLHEAD,LLPRED,HALLOC,HGET1
        EXTERNAL ZINIT,REMARK,ZQUIT

        CALL ZINIT

        CALL REMARK('Heap & List Sub-library Test Program')

        CALL HINIT(HEAP,20000)

        DO 100 I=1,100
            A(I)=HALLOC(HEAP,I+50)
 100    CONTINUE

        DO 200 I=2,100,2
            CALL HFREE(HEAP,A(I))
 200    CONTINUE

        DO 300 I=2,100,2
            A(I)=HALLOC(HEAP,70+I)
 300    CONTINUE

        DO 400 I=1,100
            CALL HFREE(HEAP,A(I))
 400    CONTINUE

        CALL REMARK('Basic HEAP test complete')

        DO 500 I=1,10
            A(I)=LLCRHE(HEAP,0)
 500    CONTINUE

        DO 600 I=11,20
            A(I)=LLCREL(HEAP,0)
 600    CONTINUE

        DO 700 I=11,20
            CALL LLINTO(HEAP,A(I),A(I-10))
 700    CONTINUE

        DO 800 I=1,10
            IF (LLFIRS(HEAP,A(I)).NE.A(I+10))
     +          CALL ERROR('LLINTO/LLFIRS failure')
            IF (LLLAST(HEAP,A(I)).NE.A(I+10))
     +          CALL ERROR('LLINTO/LLLAST failure')
            IF (LLNEXT(HEAP,A(I+10)).NE.0) CALL ERROR('LLNEXT failure')
            IF (LLPREV(HEAP,A(I+10)).NE.0) CALL ERROR('LLPREV failure')
            IF (LLPRED(HEAP,A(I+10)).NE.A(I))
     +          CALL ERROR('LLPRED failure 1')
            IF (LLPRED(HEAP,A(I)).NE.A(I+10))
     +          CALL ERROR('LLPRED failure 2')
            IF (LLHEAD(HEAP,A(I+10)).NE.A(I))
     +          CALL ERROR('LLHEAD failure 1')
 800    CONTINUE

        I=HGET1(HEAP)
        IF (I.EQ.HGET1(HEAP)) CALL ERROR('HGET1 failure')
        HEAP(I)=0
        HEAP(HGET1(HEAP))=0

        CALL LLOUT(HEAP,A(11))
        IF (LLFIRS(HEAP,A(1)).NE.0) CALL ERROR('LLOUT failure 1')
        IF (LLLAST(HEAP,A(1)).NE.0) CALL ERROR('LLOUT failure 1A')
        IF (LLPRED(HEAP,A(11)).NE.0) CALL ERROR('LLOUT failure 1B')
        IF (LLNEXT(HEAP,A(11)).NE.0) CALL ERROR('LLOUT failure 1C')
        CALL LLFOLL(HEAP,A(11),A(1))
        IF (LLFIRS(HEAP,A(1)).NE.A(11)) CALL ERROR('LLFOLL failure 1')
        IF (LLLAST(HEAP,A(1)).NE.A(11)) CALL ERROR('LLFOLL failure 1A')
        IF (LLPREV(HEAP,A(11)).NE.0) CALL ERROR('LLFOLL failure 1B')
        IF (LLNEXT(HEAP,A(11)).NE.0) CALL ERROR('LLFOLL failure 1C')
        IF (LLPRED(HEAP,A(11)).NE.A(1)) CALL ERROR('LLFOLL failure 1D')
        CALL LLFOLL(HEAP,A(11),A(12))
        IF (LLFIRS(HEAP,A(1)).NE.0) CALL ERROR('LLFOLL failure 2')
        IF (LLFIRS(HEAP,A(2)).NE.A(12)) CALL ERROR('LLFOLL failure 3')
        IF (LLLAST(HEAP,A(2)).NE.A(11)) CALL ERROR('LLFOLL failure 4')
        IF (LLNEXT(HEAP,A(12)).NE.A(11)) CALL ERROR('LLFOLL failure 5')
        IF (LLPREV(HEAP,A(11)).NE.A(12)) CALL ERROR('LLFOLL failure 6')
        IF (LLHEAD(HEAP,A(11)).NE.LLHEAD(HEAP,A(12)))
     +      CALL ERROR('LLHEAD failure 2')
        CALL LLFOLL(HEAP,A(13),A(2))
        IF (LLFIRS(HEAP,A(3)).NE.0) CALL ERROR('LLFOLL failure 7')
        IF (LLFIRS(HEAP,A(2)).NE.A(13)) CALL ERROR('LLFOLL failure 8')
        IF (LLLAST(HEAP,A(2)).NE.A(11)) CALL ERROR('LLFOLL failure 9')
        IF (LLNEXT(HEAP,A(13)).NE.A(12)) CALL ERROR('LLFOLL failure 10')
        IF (LLPREV(HEAP,A(12)).NE.A(13)) CALL ERROR('LLFOLL failure 11')
        IF (LLNEXT(HEAP,A(11)).NE.0) CALL ERROR('LLFOLL failure 12')
        CALL LLINTO(HEAP,A(14),A(2))
        IF (LLLAST(HEAP,A(2)).NE.A(14)) CALL ERROR('LLINTO failure 2')
        CALL LLOUT(HEAP,A(13))
        IF (LLFIRS(HEAP,A(2)).NE.A(12)) CALL ERROR('LLOUT failure 2')
        IF (LLPREV(HEAP,A(12)).NE.0) CALL ERROR('LLOUT failure 2')
        CALL LLDELE(HEAP,A(12))
        IF (LLFIRS(HEAP,A(2)).NE.A(11)) CALL ERROR('LLDELE failure')
        CALL LLDELH(HEAP,A(1))

C LLCRHD/LLCRED not tested

        CALL REMARK('Test Complete.')
        CALL ZQUIT(-2)

        END
